﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Com.GUI.LibraryManager.Controls.SubControl;
using System.Media;
using System.Linq;

namespace Com
{
    /// <summary>
    /// Interaction logic for ucAirCeiling.xaml
    /// </summary>
    public partial class ucAirCeiling : UserControl
    {
        ucAirCeilingType uc1;
        ucAirCeilingStructure uc2;
        ucAirCeilingLayer uc3;
        ucAirCeilingHeat uc4;

        public ucAirCeiling()
        {
            this.InitializeComponent();

        }

        private void cbxCoefficientType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            dockPanel1.Children.Clear();
            loadUC();
        }

        private void loadUC()
        {
            if (cbxCoefficientType.SelectedIndex == 0)
            {
                uc1 = new ucAirCeilingType();
                dockPanel1.Children.Add(uc1);
            }
            if (cbxCoefficientType.SelectedIndex == 1)
            {
                uc2 = new ucAirCeilingStructure();
                dockPanel1.Children.Add(uc2);
            }
            if (cbxCoefficientType.SelectedIndex == 2)
            {
                uc3 = new ucAirCeilingLayer();
                dockPanel1.Children.Add(uc3);
            }
            if (cbxCoefficientType.SelectedIndex == 3)
            {
                uc4 = new ucAirCeilingHeat();
                dockPanel1.Children.Add(uc4);
            }
        }


        public void enableButton()
        {
            btnCancel.IsEnabled = false;
            btnSave.IsEnabled = false;

            btnNew.IsEnabled = true;
            btnDelete.IsEnabled = true;
            btnCopy.IsEnabled = true;
        }

        public void disableButton()
        {
            btnCancel.IsEnabled = true;
            btnSave.IsEnabled = true;

            btnNew.IsEnabled = false;
            btnDelete.IsEnabled = false;
            btnCopy.IsEnabled = false;
        }

        private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            cbxCoefficientType.SelectedIndex = 0;
            enableButton();
        }

        private void btnNew_Click(object sender, RoutedEventArgs e)
        {
            if (cbxCoefficientType.SelectedIndex == 0)
            {

            }
            if (cbxCoefficientType.SelectedIndex == 1)
            {
                disableButton();
                uc2.addNew();
            }
            if (cbxCoefficientType.SelectedIndex == 2)
            {
                disableButton();
                uc3.addNew();
            }
            if (cbxCoefficientType.SelectedIndex == 3)
            {
                disableButton();
                uc4.addNew();
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            enableButton();
            if (cbxCoefficientType.SelectedIndex == 0)
            {

            }
            if (cbxCoefficientType.SelectedIndex == 1)
            {
                uc2.reloadData();
            }
            if (cbxCoefficientType.SelectedIndex == 2)
            {

            }
            if (cbxCoefficientType.SelectedIndex == 3)
            {

            }
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {

            if (cbxCoefficientType.SelectedIndex == 0)
            {

            }
            if (cbxCoefficientType.SelectedIndex == 1)
            {
                uc2.saveData();
            }
            if (cbxCoefficientType.SelectedIndex == 2)
            {
                uc3.saveData();
            }
            if (cbxCoefficientType.SelectedIndex == 3)
            {
                uc4.saveData();
            }
            enableButton();
        }

        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult rs = MessageBox.Show("Do you want to delete this item?", "Confirm", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
            if (rs == MessageBoxResult.OK)
            {
                if (cbxCoefficientType.SelectedIndex == 0)
                {

                }
                if (cbxCoefficientType.SelectedIndex == 1)
                {
                    uc2.deleteData();
                }
                if (cbxCoefficientType.SelectedIndex == 2)
                {
                    uc3.delData();
                }
                if (cbxCoefficientType.SelectedIndex == 3)
                {
                    uc4.deleteData();
                }
            }
            
        }

        private void btnCopy_Click(object sender, RoutedEventArgs e)
        {
            if (cbxCoefficientType.SelectedIndex == 0)
            {

            }
            if (cbxCoefficientType.SelectedIndex == 1)
            {
                disableButton();
                uc2.copyData();

            }
            if (cbxCoefficientType.SelectedIndex == 2)
            {
                disableButton();
                uc3.copyData();
            }
            if (cbxCoefficientType.SelectedIndex == 3)
            {
                disableButton();
            }
        }

    }
}